package demoMod.stsconsole.cards.red;

import demoMod.stsconsole.cards.AbstractCard;
import demoMod.stsconsole.characters.AbstractPlayer;
import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.helpers.DamageInfo;
import demoMod.stsconsole.helpers.LocalizedStrings;
import demoMod.stsconsole.interfaces.TurnStartSubscriber;

import java.util.List;

public class BodySlam extends AbstractCard implements TurnStartSubscriber {
    public static final String ID = "BodySlam";

    public BodySlam() {
        super(ID);
        this.baseDamage = 0;
        this.color = CardColor.RED;
        this.cost = 1;
        this.rarity = CardRarity.COMMON;
        this.type = CardType.ATTACK;
        this.target = CardTarget.ENEMY;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.cost = 0;
            this.upgraded = true;
            this.name = this.name + "+";
            this.upgradeTimes++;
        }
    }

    @Override
    public boolean use(AbstractPlayer p, AbstractCreature target) {
        if (target != null) {
            target.damage(new DamageInfo(this.damage, p));
        }
        return true;
    }

    @Override
    public void calculateCardDamage(AbstractCreature target) {
        this.baseDamage = AbstractDungeon.player.getCurrentBlock();
        super.calculateCardDamage(target);
        this.baseDamage = 0;
    }

    @Override
    public void onReloadStrings() {
        AbstractPlayer p = AbstractDungeon.player;
        if (p != null && (p.drawPile.contains(this) ||
            p.hand.contains(this) ||
            p.discardPile.contains(this) ||
            p.exhaustPile.contains(this))) {
            atTurnStart(true);
        } else {
            super.onReloadStrings();
        }
    }

    @Override
    public void atTurnStart(boolean isPlayer) {
        List<String> cardStrings = LocalizedStrings.getCardStrings(this.id);
        this.description = cardStrings.get(1) + cardStrings.get(2);
    }
}
